<?php
include ("./includes/header.php");
include ("./includes/iniciaSessio.php");
include ("./includes/connection.php");

include ("./includes/registreInicial.php");
include ("./includes/login.php");
?>

<body>
	<?php
	include ("./includes/contentHeader.php");
	?>
	<!--finestre modal-->
	<!--<div class="modal-footer">
	<a href="#" class="btn">Close</a>
	<a href="#" class="btn btn-primary">Save changes</a>
	</div>
	</div>-->
	<!-- fi finestre-->
	<div class="container">
		<section class="hero-unit ">
			<form class="well form-inline"  id="buscarRuta" name="buscarRuta" action="#" method="post">
				<div class="control-group">
					<div class="controls">
						<input type="text" class="span5" id="origen" name="origen" placeholder="Origen" >
					</div>
				</div>
				<div class="control-group">
					<div class="controls">
						<input type="text" class="span5" id="desti" name="desti" placeholder="Destí" >
					</div>
				</div>
				<button type="button" class="enviarFrm btn" id="buscar">
					<!--fer comprovacio de k tots el camps estan plens i despres enviar a calcRoute()-->
					Cerca
				</button>
				<button type="button" class="enviarFrm btn" id="buscaravançat">
					<!--fer comprovacio de k tots el camps estan plens i despres enviar a calcRoute()-->
					Cerca avançada
				</button>
			</form>
			<div id="map_canvas" style="width: 100%; height: 400px; overflow-x: hidden; overflow-y: hidden; "></div>
			<div id="map_Ruta" ></div>
		</section>
	</div>
	<div class="container">
		<section class="row-fluid">
			<div id="resultatCerca"></div>
			<div class="span8" id="viatgesPublicats">
				<h2>Viatges publicats</h2>
				<hr>
				<?php
//'recorregut.idProvinciaInicial' in 'on clause'
$sql = "select recorregut.*, ruta.adresaOrigen, ruta.adresaFinal, usuari.alias, usuari.foto from(recorregut join usuari on recorregut.idUsuari=usuari.idUsuari) join ruta on recorregut.idRuta=ruta.idRuta order by recorregut.idRuta DESC limit 8";

$result = mysql_query($sql, $conexion) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$id=$row['idRuta'];

$idRecorregutTotal = $row['idRecorregut'];
				?>
				<table border="6" style="width: 100%; height: 100px;">
					<tr bgcolor="<?php
					if ($row['idTipusUsuari'] == 'CND') {
						echo "#33CCFF";
					}
					if ($row['idTipusUsuari'] == 'PSG') {
						echo "#00CC66";
					}
					?>">
						<th rowspan="2"><img src="<?php echo $row['foto'];?>" alt='foto' height='100' width='100'/></th>
						<th><?php echo $row['alias'];?></th>
						<th><?php
						if ($row['data'] != '0000-00-00')
						{
							echo $row['data'];
						}
						if ($row['dl'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/lunes_si.png' width='25' height='25'/>";
						}
						if ($row['dl'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/lunes.png' width='25' height='25'/>";
						}
						if ($row['dt'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/martes_si.png' width='25' height='25'/>";
						}
						if ($row['dt'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/martes.png' width='25' height='25'/>";
						}
						if ($row['dc'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/miercoles_si.png' width='25' height='25'/>";
						}
						if ($row['dc'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/miercoles.png' width='25' height='25'/>";
						}
						if ($row['dj'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/jueves_si.png' width='25' height='25'/>";
						}
						if ($row['dj'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/jueves.png' width='25' height='25'/>";
						}
						if ($row['dv'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/viernes_si.png' width='25' height='25'/>";
						}
						if ($row['dv'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/viernes.png' width='25' height='25'/>";
						}
						if ($row['ds'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/sabado_si.png' width='25' height='25'/>";
						}
						if ($row['ds'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/sabado.png' width='25' height='25'/>";
						}
						if ($row['dg'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/domingo_si.png' width='25' height='25'/>";
						}
						if ($row['dg'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/domingo.png' width='25' height='25'/>";
						}
						?></th>
					</tr>
					<tr>
						<td><a href="oferta_ruta.php?id=<?php echo $id;?>"><?php echo $row['adresaOrigen'];?>  -  <?php echo $row['adresaFinal'];?></a></td>
						<td>Preu: <?php echo $row['preu'];?>€ Nº Places: <?php echo $row['nPlaces'];?></td>
					</tr>
				</table>
				<?php
				}
				?>
			</div>
			<div class="span3 offset12">
				<?php
				if (isset($_SESSION["nom"]) and isset($_SESSION["username"])) {
					echo '<a href="publicar_viatge.php"><img src="images/publicar_viaje.jpg" title="Publica el teu viatge" alt="Publicar viatge" width="250" height="170"></a>';
				}
				if (!isset($_SESSION["nom"]) and !isset($_SESSION["username"])) {
					echo '<a href="registre.php"><img src="images/publicar_viaje.jpg" title="Publica el teu viatge" alt="Publicar viatge" width="250" height="170"></a>';
				}
				if (!isset($_SESSION["nom"]) and isset($_SESSION["username"])) {
					echo '<a href="registre.php"><img src="images/publicar_viaje.jpg" title="Publica el teu viatge" alt="Publicar viatge" width="250" height="170"></a>';
				}
				?>
			</div>
		</section>
	</div>
	<hr>
</body>
<?php
include ("./includes/footer.php");
echo '<script src="./js/mapsInici.js"></script>';
?>

